<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateProductsTable extends Migration
{
    public function up()
    {
        Schema::create('products', function (Blueprint $table) {
            $table->id();
	        $table->unsignedBigInteger('vendor_id')->index()->default(0)->nullable()->comment('belongs to this vendor');
	        $table->unsignedBigInteger('command_user_id')->index()->default(0)->nullable()->comment('推荐人ID');
	        $table->unsignedBigInteger('category_id')->index()->default(0)->nullable()->comment('belongs to this category');
	        $table->unsignedBigInteger('brand_id')->index()->default(0)->nullable()->comment('belongs to this brand');
	        $table->unsignedBigInteger('attribute_group_id')->index()->default(0)->nullable()->comment('belongs to this attribute group');
	        $table->string('title')->index();
	        $table->string('title_long')->nullable()->index();
	        $table->string('code')->nullable()->index()->comment('product code');
	        $table->text('description')->nullable();
	        $table->text('recommendation')->nullable();
	        $table->text('command_link')->nullable()->comment('推荐链接');
	        
	        $table->string('cover')->nullable()->comment('cover image');
	        $table->decimal('price_lowest_cost', 10, 2)->nullable()->comment('lowest price cost of all skus');
	        $table->decimal('price_lowest', 10, 2)->nullable()->comment('lowest price of all skus');
	        $table->decimal('price_market', 10, 2)->nullable()->comment('market price');
	        $table->unsignedInteger('sold_count')->default(0);
	        $table->unsignedInteger('comment_count')->default(0);
	        $table->integer('comment_favor_rate')->default(100);
	        $table->boolean('is_subsidy')->default(false);
	        $table->boolean('is_hongkong_direct')->default(false);
	        $table->boolean('is_overseas_direct')->default(false);
	        $table->boolean('is_delivery_free')->default(true);
	        $table->boolean('is_sf')->default(false);
	        $table->boolean('is_returnable')->default(false)->comment('if support returnable service after sale');
	        $table->boolean('is_sale')->default(true);
	        $table->boolean('is_top')->default(false);
	        $table->boolean('is_pop')->default(false)->comment('strong recommend');
	        $table->boolean('is_rec')->default(false)->comment('recommendation');
	        $table->boolean('is_new')->default(false);
	        $table->boolean('is_hot')->default(false);
	        $table->boolean('is_top_100')->default(false);
	        $table->boolean('is_gold_storm')->default(false);
	        $table->boolean('is_gold_bean')->default(false);
	        $table->unsignedBigInteger('order')->default(100000000);
	        $table->softDeletes();
	        $table->timestamps();
        });
    }

    public function down()
    {
        Schema::dropIfExists('products');
    }
}
